/********************************************
 * SV。Com call banner 与平台通信网关callgate通讯接口定义
 * @Function ：为 callbanner 、 crm 提供通信平台相关查询类服务
 * @author   :
 * @create   : 
 * @Companny : 
 ********************************************/
var cmsHelper = function() {
    //全局变量定义区
    var g_TokenId = ""; //企业令牌，除鉴权交易外须随head上送主机
    var g_EntId = 0; //企业编码
    var g_OptId = ""; //当前坐席的工号，每次交易时须在 head中加入
    var g_Queueid = 0; //当前坐席的队列号，该参数暂时没用，因为坐席可加入多个队列，该值会变
    var g_CmsUrl = "service/softphonesvc";
    var HOST_GETENTTOKEN = 5000; //企业坐席鉴权
    var HOST_REGISTAGENT = 5001;
    /****
     * 以下的交易均须鉴权通过后才能使用，如果返回 errcode=3 用户鉴权失败, 则须再次调用鉴权重新获取tokenid
     */

    var HOST_GETACDINFO = 5002; // 获取坐席的acd信息
    var HOST_GETAGCSTATUS = 5003; //查询单个坐席状态
    var HOST_GETMYQUEAGCSSTATUS = 5004; //查询当前队列所有坐席状态
    var HOST_GETAGCCDRLOGS = 5005; // 获取坐席通话流水
    var HOST_GETAGCRECORDS = 5006; //获取坐席通话录音
    var HOST_PACKAGCRECORDS = 5007; //下载单页坐席通话录音 , 配合录音翻页查询，打包下载
    var HOST_GETAGCOPTLOGS = 5008; // 获取坐席操作流水
    var HOST_GETENTCDRLOGS = 5009; // 获取企业坐席通话流水
    var HOST_GETENTRECORDS = 5010; //获取企业录音日志 可选择单个坐席	
    var HOST_PACKENTRECORDS = 5011; //打包下载企业录音日志'	
    var HOST_PACKENTDAYRECS = 5012; // 打包企业一天录音
    var HOST_GETENTQUEUES = 5013; // 获取企业队列
    var HOST_GETRECORDFILE = 5014; //获取单个录音url
    var HOST_GETSERVERINFO = 5015; //获取服务器信息	
    var HOST58_AGCMONITOR = 6006; //发送当前被监听对象信息
    /***
     *获取flashgate的节点 
     **/
    var HOST_GETSERVICENODE = 5016;
    /*58 项目，坐席新呼叫--呼出流水记录 */
    var HOST58_AGENTNEWCALL = 6001;
    //通话结束
    var HOST58_AGENTENDCALL = 6002;

    var Tr58_GetAgcStatus = 6003;


    // 统计页面查询
    var Tr58_GetStatisticsPage = 6005;

    /***
     * 以下是查询翻页需要用到的参数 
     */
    var g_CurTrCode = 0;
    var g_MinSn = 0; //明细中最小traceno
    var g_MaxSn = 0; //明细中最大traceno
    var g_PageSize = 20; //单页查询的最大记录笔数，不能超过50条 
    var g_SortOrder = "asc"; //排序方式 asc升序，desc降序 
    var g_LastQryStr = ""; //最近查询条件，如果变了需要重置 minsn/maxsn等参数
    //录音打包时用
    var g_BeginTime = "";
    var g_WorkNo = "";
    var g_EndTime = "";
    var g_FSNodeId = 0; //坐席登录的fs服务节点
    /********************************************
     * 交易报文打包 
     * @param trCode ：交易码
     * @author trBody ：交易正文
     * @returns {String} 
     ********************************************/
    function packHost(trCode, trBody) {
        var headStr = "\"head\":{\"hostcode\":\"" + trCode + "\",\"entid\":" + g_EntId + ",\"optid\":\"" + g_OptId + "\",\"tokenid\":\"" + g_TokenId + "\"}";
        var bodyStr = "\"body\":" + JSON.stringify(trBody);
        return "{" + headStr + "," + bodyStr + "}";
    }

    //JSON转换为字符串
    function JSONstringify(Json) {
        if ($.browser.msie) {
            if ($.browser.version == "7.0" || $.browser.version == "6.0") {
                var result = jQuery.parseJSON(Json);
            } else {
                var result = JSON.stringify(Json);
            }
        } else {
            var result = JSON.stringify(Json);
        }
        return result;
    }

    //public api refence SV-callbanner develop manu
    return {
        /******************************************
         * 配置监控中心地址
         * @param cmsUrl
         * @returns
         * 注意：当系统启动后，参数将从服务器获取后台服务相关的运行参数
         *    cms为主备服务模式，将提供两套服务参数，当主机出现故障后可自动切换备用服务
         *****************************************/
        setCmsUrl: function(cmsUrl) {
            g_CmsUrl = cmsUrl;
            console.log('cmsurl = ' + g_CmsUrl);
        },
        /**
         * 坐席token信息配置
         * @param entId 
         * @param optId 坐席号
         * @param tokenId
         * @returns
         */
        setAuthInfo: function(entId, optId, tokenId) {
            g_TokenId = tokenId;
            g_EntId = entId;
            g_OptId = optId;
        },

        /**********************************************
         * 企业及坐席工号鉴权
         * @param entId ：企业编号
         * @param optId ：当前坐席工号
         * return
         *     成功：返回TokenId、queueid
         *     失败：具体原因
         *  特别提醒，该交易涉及到企业密码安全，建议在后台实现，并将 tokenid
         *    返回前端   
         **********************************************/
        getEntToken: function(callback_func, entId, entPwd, optId) {
            if (entId.length == 0 || optId.length == 0) {
                return callback_func(-1, "企业编号或工号不能为空!");
            }
            g_EntId = entId;
            g_OptId = optId;
            var trBody = { //交易请求正文  
                "entpwd": entPwd,
                "workno": optId
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETENTTOKEN, trBody),
                dataType: 'json', //很重要!!!.      预期服务器返回的数据类型   
                type: "post",
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!");
                },
                success: function(data) {
                    // showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        g_TokenId = data.body.tokenid;
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body); //获取token成功，回调callbanner-ctrl中鉴权成功
                }
            });
        },

        /****************************************
         * 自动注册，此功能比较危险强烈建议后台执行
         * @param callback_func  回调，注册完成后执行
         * @param entId       企业id
         * @param userName    坐席名字
         * @param optId       坐席工号
         * @param queueId     坐席队列号，0表示空
         * @param telNo       坐席手机或固话
         * @returns
         */
        /* registAgent:function (callback_func,entId,userName,optId,queueId,telNo)
		 {   		     
			 g_EntId = entId ;
		     g_OptId = optId ;   
		     var trBody = {
		             "workno":optId,
		             "workname":userName,
		             "telno":telNo,
		             "queueid":queueId		             
		         }		       
		     $.ajax({   
		             url:g_CmsUrl,   
		             data:packHost(HOST_REGISTAGENT,trBody),    
		             dataType:'json', //很重要!!!.      预期服务器返回的数据类型   
		             type: "post",
		             error:function(){   
		            	return callback_func(1, "网络故障请稍后再试!",null);   
		             },                    
		             success:function(data){
		            	 //showMessage(data.head.errcode, data.head.errmsg );
        		        return callback_func(data.head.errcode,data.head.errmsg,data.body) ;
		             }   
		     });
		 },*/

        /*-----------------下面的交易提供给 通信。CALL BANNER 使用-----------------------**/
        /**********************************************
         * 获取坐席的ACD信息， callbanner的注册参数 
         * return
         *     成功：返回acd info
         *     失败：具体原因
         **********************************************/
        getAcdInfo: function(callback_func) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "workno": g_OptId
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETACDINFO, trBody),
                dataType: 'json', //很重要!!!.      预期服务器返回的数据类型   
                type: "post",
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    //showMessage(data.head.errcode, data.head.errmsg );
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },

        /*****************************************
         *  sipphone serverinfo
         ***************************************/
        getServerInfo: function(callback_func) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "workno": g_OptId
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETSERVERINFO, trBody),
                dataType: 'json', //很重要!!!.      预期服务器返回的数据类型   
                type: "post",
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },
        /*发送被监听者的信息
         */
        sendAgcMonitorInfo: function(callback_func, monitor, agc) {
            var trBody = {
                    "monitor": monitor, // 工号或姓名
                    "agc": agc
                }
                //alert("callbanner+ AgcListState");
            $.ajax({

                url: g_CmsUrl,
                data: packHost(HOST58_AGCMONITOR, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    if (callback_func)
                        return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    if (data.head.errcode == 0) {
                        return callback_func&&callback_func(data.head.errcode,
                            data.head.errmsg, data.body);
                    }
                }
            });
        },


        /*****************************************
         * 获取坐席的服务节点，nodeid为节点号，首次登陆是=0， 
         * 下次为坐席对fs的心跳检测，此时须送正使用的节点号
         ***************************************/
        getServiceNode: function(callback_func, extNum) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "workno": g_OptId,
                "extnum": extNum,
                "nodeid": g_FSNodeId //0普通，1 话机ha
            };
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETSERVICENODE, trBody),
                dataType: 'json', //很重要!!!.      预期服务器返回的数据类型   
                type: "post",
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    if (data.head.errcode == 0) {
                        g_FSNodeId = data.body.nodeid;
                    }
                    if (callback_func) {
                        return callback_func(data.head.errcode, data.head.errmsg, data.body);
                    }
                }
            });
        },

        /**********************************************
         * 获取坐席的状态， 
         * return
         *     成功：
         **********************************************/
        getAgcState: function(callback_func) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "workno": g_OptId
            }

            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETAGCSTATUS, trBody),
                dataType: 'json', //很重要!!!.      预期服务器返回的数据类型   
                type: "post",
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },

        /**********************************************
         * 获取企业队列 
         * return
         *     成功：
         **********************************************/
        getEntQueueList: function(callback_func) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            alert("g_TokenId:"+g_TokenId);
            var trBody = {}
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETENTQUEUES, trBody),
                dataType: 'json', //很重要!!!.      预期服务器返回的数据类型   
                type: "post",
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },


        /**********************************************
         * 查询页size及排序方式设置
         *   sortorder : desc 或asc  按照记录的主键进行排序
         *   pagesize  : 单页的查询笔数，不超过 50
         **********************************************/
        setQueryParam: function(sortOrder, pagesize) {
            g_SortOrder = sortOrder;
            g_PageSize = pageSize;
        },
        /**********************************************
         * 获取坐席所在组全部坐席的状态， 
         * @param callback_func 回调函数
         * @param qId           队列id
         * @param workno        工号或者姓名
         * @param states   坐席状态集合
         * @param toNext : 0 上一页，1 下一页
         **********************************************/
        getQueueAgcState: function(callback_func, qId, workno, states, toNext) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var tmpQryStr = HOST_GETMYQUEAGCSSTATUS + "_" + qId + workno + states + toNext;
            if (g_LastQryStr != tmpQryStr) {
                g_MinSn = 0;
                g_MaxSn = 0;
                g_SortOrder = "asc";
                g_LastQryStr = tmpQryStr;
            }
            var trBody = {
                "queueid": qId,
                "workno": workno, //工号或姓名
                "states": states,
                "minsn": g_MinSn,
                "maxsn": g_MaxSn,
                "pagesize": g_PageSize,
                "sortorder": g_SortOrder,
                "tonext": toNext
            }
            $.ajax({
                url: g_CmsUrl,
                //data:{trtxt:packHost(HOST_GETMYQUEAGCSSTATUS,trBody)},    
                data: packHost(HOST_GETMYQUEAGCSSTATUS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    if (data.head.errcode == 0) {
                        if (data.body.detailnum > g_PageSize) {
                            g_MinSn = data.body.minsn;
                            g_MaxSn = data.body.maxsn;
                        } else {
                            g_MinSn = 0;
                            g_MaxSn = 0;
                        }
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },

        /*-----------------下面的交易提供给 CRM 系统使用-----------------------**/


        /**********************************************
         * 获取坐席通话流水 
         * @param toNext : 0 上一页，1 下一页
         * @param begintime : "2016-01-01 08:10:00",
         * return
         *     成功：
         **********************************************/
        getAgcCdrPage: function(callback_func, toNext, beginTime, endTime) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var tmpQryStr = HOST_GETAGCCDRLOGS + "_" + beginTime + endTime + toNext;
            if (g_LastQryStr != tmpQryStr) {
                g_MinSn = 0;
                g_MaxSn = 0;
                g_SortOrder = "asc";
                g_LastQryStr = tmpQryStr;
            }

            var trBody = {
                "workno": g_OptId,
                "begintime": beginTime, // "2016-01-01 08:10:00",
                "endtime": endTime, // "2016-08-11 08:10:00",             
                "minsn": g_MinSn,
                "maxsn": g_MaxSn,
                "pagesize": g_PageSize,
                "sortorder": g_SortOrder,
                "tonext": toNext
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETAGCCDRLOGS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    if (data.head.errcode == 0) {
                        g_MinSn = data.body.minsn;
                        g_MaxSn = data.body.maxsn;
                        g_BeginTime = beginTime,
                            g_EndTime = endTime;
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },

        /**********************************************
         * 获取坐席通话录音
         * @param toNext : 0 上一页，1 下一页
         * @param begintime : "2016-01-01 08:10:00", 
         * return
         *     成功：
         **********************************************/
        getAgcRecordPage: function(callback_func, toNext, beginTime, endTime) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var tmpQryStr = HOST_GETAGCRECORDS + "_" + beginTime + endTime + toNext;
            if (g_LastQryStr != tmpQryStr) {
                g_MinSn = 0;
                g_MaxSn = 0;
                g_SortOrder = "asc";
                g_LastQryStr = tmpQryStr;
            }

            var trBody = {
                "workno": g_OptId,
                "begintime": beginTime, // "2016-01-01 08:10:00",
                "endtime": endTime, // "2016-08-11 08:10:00",             
                "minsn": g_MinSn,
                "maxsn": g_MaxSn,
                "pagesize": g_PageSize,
                "sortorder": g_SortOrder,
                "tonext": toNext
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETAGCRECORDS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    // showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        g_MinSn = data.body.minsn;
                        g_MaxSn = data.body.maxsn;
                        g_BeginTime = beginTime,
                            g_EndTime = endTime;

                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);

                }
            });
        },
        /**********************************************
         * 打包下载单页坐席通话录音 
            该函数配合录音查询用、通话流水灯
         * @param toNext : 0 上一页，1 下一页
         * @param begintime : "2016-01-01 08:10:00", 
         * return
         *     成功：
         **********************************************/
        packAgcRecordPage: function(callback_func) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "workno": g_OptId,
                "begintime": g_BeginTime,
                "endtime": g_EndTime, // "2016-08-11 08:10:00",             
                "minsn": g_MinSn,
                "maxsn": g_MaxSn
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_PACKAGCRECORDS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    // showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        //  $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   
                        // return ;
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);

                }
            });
        },



        /**********************************************
         * 获取坐席操作流水 
         * @param toNext : 0 上一页，1 下一页
         * @param begintime : "2016-01-01 08:10:00", 
         * return
         *     成功：
         **********************************************/
        getAgcOptPage: function(callback_func, toNext, beginTime, endTime) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var tmpQryStr = HOST_GETAGCOPTLOGS + "_" + beginTime + endTime + toNext;
            if (g_LastQryStr != tmpQryStr) {
                g_MinSn = 0;
                g_MaxSn = 0;
                g_SortOrder = "asc";
                g_LastQryStr = tmpQryStr;
            }
            var trBody = {
                "workno": g_OptId,
                "begintime": beginTime, // "2016-01-01 08:10:00",
                "endtime": endTime, // "2016-08-11 08:10:00",             
                "minsn": g_MinSn,
                "maxsn": g_MaxSn,
                "pagesize": g_PageSize,
                "sortorder": g_SortOrder,
                "tonext": toNext
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETAGCOPTLOGS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {

                    if (data.head.errcode == 0) {
                        g_MinSn = data.body.minsn;
                        g_MaxSn = data.body.maxsn;
                        //     $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   

                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },


        /**********************************************
         * 获取企业所有坐席通话流水 
         * @param workNo : 坐席工号， 管理员可以查看其它坐席的流水，为空则所有坐席
         * @param toNext : 0 上一页，1 下一页
         * @param begintime : "2016-01-01 08:10:00", 
         * return
         *     成功：
         **********************************************/
        getEntCdrPage: function(callback_func, workNo, toNext, beginTime, endTime) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var tmpQryStr = HOST_GETENTCDRLOGS + "_" + beginTime + endTime + workNo + toNext;
            if (g_LastQryStr != tmpQryStr) {
                g_MinSn = 0;
                g_MaxSn = 0;
                g_SortOrder = "asc";
                g_LastQryStr = tmpQryStr;
            }
            var trBody = {
                "workno": workNo,
                "begintime": beginTime, // "2016-01-01 08:10:00",
                "endtime": endTime, // "2016-08-11 08:10:00",             
                "minsn": g_MinSn,
                "maxsn": g_MaxSn,
                "pagesize": g_PageSize,
                "sortorder": g_SortOrder,
                "tonext": toNext
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETENTCDRLOGS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    // showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        g_MinSn = data.body.minsn;
                        g_MaxSn = data.body.maxsn;
                        g_BeginTime = beginTime,
                            g_EndTime = endTime;
                        //  $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   

                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },

        /**********************************************
         * 获取企业所有坐席通话录音 
         * @param workNo : 坐席工号， 管理员可以查看其它坐席的流水，为空则所有坐席
         * @param toNext : 0 上一页，1 下一页
         * @param begintime : "2016-01-01 08:10:00", 
         * return
         *     成功：
         **********************************************/
        getEntRecordPage: function(callback_func, workNo, toNext, beginTime, endTime) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var tmpQryStr = HOST_GETENTRECORDS + "_" + beginTime + endTime + workNo + toNext;
            if (g_LastQryStr != tmpQryStr) {
                g_MinSn = 0;
                g_MaxSn = 0;
                g_SortOrder = "asc";
                g_LastQryStr = tmpQryStr;
            }
            var trBody = {
                "workno": workNo,
                "begintime": beginTime, // "2016-01-01 08:10:00",
                "endtime": endTime, // "2016-08-11 08:10:00",             
                "minsn": g_MinSn,
                "maxsn": g_MaxSn,
                "pagesize": g_PageSize,
                "sortorder": g_SortOrder,
                "tonext": toNext
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETENTRECORDS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    // showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        g_MinSn = data.body.minsn;
                        g_MaxSn = data.body.maxsn;
                        g_BeginTime = beginTime,
                            g_EndTime = endTime;
                        g_WorkNo = workNO;
                        //   $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },
        /**********************************************
         * 获取企业所有坐席通话录音 
         * @param workNo : 坐席工号， 管理员可以查看其它坐席的流水，为空则所有坐席
         * @param toNext : 0 上一页，1 下一页
         * @param begintime : "2016-01-01 08:10:00", 
         * return
         *     成功：
         **********************************************/
        packEntRecordPage: function(callback_func) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "workno": g_WorkNo,
                "begintime": g_BeginTime, // "2016-01-01 08:10:00",
                "endtime": g_EndTime, // "2016-08-11 08:10:00",             
                "minsn": g_MinSn,
                "maxsn": g_MaxSn
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_PACKENTRECORDS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    //	 showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        //  $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   
                        //	 return ;
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },
        /**********************************************
         * 获取企业所有坐席通话录音一天 
         * @param qryDate : "2016-01-01", 
         * return
         *     成功：
         **********************************************/
        packEntDayRecord: function(callback_func, qryDate) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "qrydate": qryDate // "2016-01-01",
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_PACKENTDAYRECS, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    // showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        //    $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   
                        // return ;
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },

        /**********************************************
         * 获取一条录音url 
         *  该函数可在查询通话流水，录音流水时调用
         * @param id : 1000293   
         * return
         *     成功：
         **********************************************/
        getRecordUrl: function(callback_func, id) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                "cdrid": id // "2016-01-01",
            }
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST_GETRECORDFILE, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    // showMessage(data.head.errcode, data.head.errmsg );
                    if (data.head.errcode == 0) {
                        // $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   
                        // return ;
                    }
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },
        /****************************************************************
         * 增加坐席呼出流水 -- 58项目专用
         * @param callback_func
         * @param bussData58
         *   2016-10-31  flyway
         * @returns
         *****************************************************************/
        addAgentCall: function(callback_func, bussData58) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            //遍历map， 打包数据
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST58_AGENTNEWCALL, bussData58),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    callback_func && callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },
        /**********************************************************
         * 挂机是坐席席呼叫流水的更新
         * direct :1 坐席挂机结束， 0 客户挂
         */
        endAgentCall: function(callback_func, callId, beginTime, direct) {
            if (g_TokenId == "") {
                return callback_func(-1, "坐席未鉴权!", null);
            }
            var trBody = {
                    "call_id": callId, // "2016-01-01",
                    "begin_time": beginTime,
                    "direct": direct
                }
                //遍历map， 打包数据
            $.ajax({
                url: g_CmsUrl,
                data: packHost(HOST58_AGENTENDCALL, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    return callback_func(data.head.errcode, data.head.errmsg, data.body);
                }
            });
        },
        /***********************************************************************
         * 获取坐席所在组全部坐席的状态，
         * 
         * @param callback_func
         *            回调函数
         * @param qId
         *            队列id
         * @param workno
         *            工号或者姓名
         * @param states
         *            坐席状态集合
         * @param toNext :
         *            0 上一页，1 下一页
         **********************************************************************/
        get58AgcListState: function(callback_func, worknos, explogout, extradata) {
            var trBody = {
                "worknos": worknos, // 工号或姓名
                "explogout": explogout
            }
            $.ajax({

                url: g_CmsUrl,
                data: packHost(Tr58_GetAgcStatus, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {
                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {
                    if (data.head.errcode == 0) {
                        return callback_func(data.head.errcode,
                            data.head.errmsg, data.body, extradata);
                    }
                }
            });
        },
        get58StatisticsPage: function(callback_func, agcids, workstarttime_start, workstarttime_end, call_state, timelen_begin, timelen_end, call_type, called_no, pageindexN, pagesizeN) {
            //						if (g_TokenId == "") {
            //							return callback_func(-1, "坐席未鉴权!", null);
            //						}
            var trBody = {
                "agcids": agcids, // 工号或姓名
                "workstarttime_start": workstarttime_start, // 呼叫时间开始
                "workstarttime_end": workstarttime_end, // 呼叫时间结束
                "call_state": call_state, // 接听状态
                "timelen_begin": timelen_begin, // 呼叫时长开始
                "timelen_end": timelen_end, // 呼叫时间结束
                "call_type": call_type,
                "called_no": called_no,
                "pageindexN": pageindexN,
                "pagesizeN": pagesizeN
            };
            $.ajax({

                url: g_CmsUrl,
                data: packHost(Tr58_GetStatisticsPage, trBody),
                dataType: 'json',
                type: 'post',
                error: function() {

                    return callback_func(1, "网络故障请稍后再试!", null);
                },
                success: function(data) {

                    if (data.head.errcode == 0) {

                        return callback_func(data.head.errcode,
                            data.head.errmsg, data.body);
                    }

                }
            });
        }

    };
}();
/***
 *  get 用法
 *  $.ajax({   
             url:g_CmsUrl,   
             data:{trtxt:packHost(HOST_GETAGCOPTLOGS,trBody)},    
             dataType:'json',
             type:'get',
             error:function(){   
                 showMessage(1, "网络故障请稍后再试!");   
             },                    
             success:function(data){
            	 showMessage(data.head.errcode, data.head.errmsg );
            	 if(data.head.errcode == 0)
            		 {            		  
            		     g_MinSn = data.body.minsn ;
            		     g_MaxSn = data.body.maxsn ;
            		     $('body').append("<div>"+JSON.stringify(data.body)+"</div>").css("color","blue");   
            	     	 return ;
            		 }
             }   
     });
 * 
 */
